package ru.hackday.wave;

import com.google.wave.api.Range;
import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

public class TestSolutionFinder extends TestCase {
  public void test() {
    check("whatever", "wh", 0, 2);
    check("whatever", "ever", 4, 8);
    check("whatever", "hat", 1, 4);
  }

  public void test2() {
    System.out.println(SpeedyServlet.getColorization(ranges(0, 15), ranges(0, 13)));
    System.out.println(SpeedyServlet.getColorization(ranges(0, 13), ranges(0, 15)));
    System.out.println(SpeedyServlet.getColorization(ranges(0, 13, 14, 15), ranges(0, 15)));
  }

  private void check(String puzzleText, String solutionText, int ... r) {
    assertEquals(ranges(r), SpeedyServlet.getSolved(puzzleText, solutionText));
  }

  public List<Range> ranges(int... r) {
    assert r.length % 2 == 0;
    ArrayList<Range> res = new ArrayList<Range>();
    for (int i = 0; i < r.length; i += 2) {
      res.add(new Range(r[i], r[i + 1]));
    }
    return res;
  }
}
